1 Public Class FrmAddSupplier
2 Dim stockID As Integer
3 Dim hOldID As Integer
4 Private Sub cmdcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdcancel.Click
5 Me.Close()
6 End Sub
7
8 Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
9 Dim i As Integer
10 If txtname.Text = "" And txtaddress.Text = "" And txtcontact.Text = "" And txtCperson.Text = "" Then
11 MsgBox("No Corresponding Data !", MsgBoxStyle.Information)
12 Exit Sub
13 End If
14
15 If Split(Me.Text, " - ")(1) = "Edit" Then
16 'Replace(Replace(Replace(TextBox1.Text, "'", "$.$"), ",", "$..$"), "`", "")
17 sqlSTR = "UPDATE tbl_suppliers SET suppname ='" & R_eplace(txtname.Text) & "', " _
18 & "suppadd ='" & R_eplace(txtaddress.Text) & "', " _
19 & "suppcontact ='" & R_eplace(txtcontact.Text) & "', " _
20 & "contactperson ='" & R_eplace(txtCperson.Text) & "', " _
21 & "supplocal ='" & txtlocal.Text & "' WHERE supp_id =" & stockID
22 ExecuteSQLQuery(sqlSTR)
23 Audit_Trail(xUser_ID, TimeOfDay, "Edit Suppliers Products ")
24 Else
25 sqlSTR = "INSERT INTO tbl_suppliers (suppname, suppadd, suppcontact, contactperson, supplocal) VALUES ('" & R_eplace(txtname.Text) & "', " _
26 & "'" & R_eplace(txtaddress.Text) & "', " _
27 & "'" & R_eplace(txtcontact.Text) & "', " _
28 & "'" & R_eplace(txtCperson.Text) & "', " _
29 & "'" & txtlocal.Text & "')"
30 ExecuteSQLQuery(sqlSTR)
31 Audit_Trail(xUser_ID, TimeOfDay, "Add New Suppliers Products ")
32 End If
33
34
35 If Split(Me.Text, " - ")(1) = "Edit" Then
36 ExecuteSQLQuery("DELETE FROM TBL_Suppliers_Product WHERE Supp_ID =" & txtid.Text)
37 For i = 0 To lstProducts.Items.Count - 1
38 'MsgBox(lstProducts.Items(i).SubItems(2).Text)
39 sqlSTR = "SELECT * FROM TBL_Category_Item_File WHERE Item_ID =" & lstProducts.Items(i).SubItems(1).Text
40 ExecuteSQLQuery(sqlSTR)
41 If sqlDT.Rows.Count > 0 Then
42 sqlSTR = "INSERT INTO TBL_Suppliers_Product (Supp_ID, Catg_ID, Item_ID, Prod_Name, Item_Price) VALUES (" & txtid.Text & ", " _
43 & lstProducts.Items(i).Text & ", " _
44 & lstProducts.Items(i).SubItems(1).Text & ", " _
45 & "'" & R_eplace(lstProducts.Items(i).SubItems(2).Text) & "', " _
46 & sqlDT.Rows(0)("Item_Price") & ")"
47
48 '& IIf(lstProducts.Items(i).SubItems(3).Text = "", 0, lstProducts.Items(i).SubItems(3).Text) & ")"
49
50 End If
51 ExecuteSQLQuery(sqlSTR)
52 Next
53 Else
54 sqlSTR = "SELECT Supp_ID FROM TBL_Suppliers ORDER BY Supp_ID DESC"
55 ExecuteSQLQuery(sqlSTR)
56 hOldID = sqlDT.Rows(0)("Supp_ID") ' When user add new Get Current ID
57 For i = 0 To lstProducts.Items.Count - 1
58 sqlSTR = "SELECT * FROM TBL_Category_Item_File WHERE Item_ID =" & lstProducts.Items(i).SubItems(1).Text
59 ExecuteSQLQuery(sqlSTR)
60 If sqlDT.Rows.Count > 0 Then
61 sqlSTR = "INSERT INTO TBL_Suppliers_Product (Supp_ID, Catg_ID, Item_ID, Prod_Name, Item_Price) VALUES (" & hOldID & ", " _
62 & lstProducts.Items(i).Text & ", " _
63 & lstProducts.Items(i).SubItems(1).Text & ", " _
64 & "'" & lstProducts.Items(i).SubItems(2).Text & "', " _
65 & sqlDT.Rows(0)("Item_Price") & ")"
66 '& lstProducts.Items(i).SubItems(3).Text & ")"
67 End If
68 ExecuteSQLQuery(sqlSTR)
69 Next
70 End If
71
72 MsgBox("Record Sucessfuly Update", MsgBoxStyle.Information)
73 'FillListView(ExecuteSQLQuery("select Supp_ID as 'Supplier ID', replace(replace(suppName,'$.$','''),'$..$',',') as 'Supplier Name', replace(replace(suppadd,'$.$','''),'$..$',',') as 'Address', suppcontact as 'Contact No', replace(replace(ContactPerson,'$.$','''),'$..$',',') as 'Contact Person' FROM tbl_suppliers ORDER BY suppName"), FrmSuppliersList.lstsupplier, 0)
74 FillListView(ExecuteSQLQuery("select Supp_ID as 'Supplier ID', replace(replace(suppname,'$.$',''''),'$..$',',') as 'Supplier Name', replace(replace(suppadd,'$.$',''''),'$..$',',') as 'Address', replace(replace(suppcontact,'$.$',''''),'$..$',',') as 'Contact No', replace(replace(contactperson,'$.$',''''),'$..$',',') as 'Contact Person' FROM tbl_suppliers ORDER BY suppName"), FrmSuppliersList.lstsupplier, 0)
75 Me.Close()
76 End Sub
77
78 Private Sub FrmAddSupplier_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
79 Me.Text = "Supplier Profile"
80 End Sub
81
82 Private Sub FrmAddSupplier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
83 If Split(Me.Text, " - ")(1) = "Edit" Then
84 stockID = globalID
85 sqlSTR = "SELECT * FROM tbl_suppliers WHERE supp_ID =" & stockID
86 ExecuteSQLQuery(sqlSTR)
87 If sqlDT.Rows.Count > 0 Then
88 txtid.Text = stockID
89 txtname.Text = R_Change(sqlDT.Rows(0)("SuppName"))
90 txtaddress.Text = R_Change(sqlDT.Rows(0)("SuppAdd"))
91 txtCperson.Text = R_Change(sqlDT.Rows(0)("ContactPerson"))
92 txtcontact.Text = R_Change(sqlDT.Rows(0)("SuppContact"))
93 txtlocal.Text = sqlDT.Rows(0)("supplocal").ToString
94 End If
95 FillListView(ExecuteSQLQuery("SELECT Catg_ID, Item_ID as 'ID', Replace(Replace(Prod_Name,'$.$',''''),'$..$',',') as 'Name' FROM TBL_Suppliers_Product WHERE Supp_ID =" & txtid.Text), lstProducts, 1)
96 Else
97 txtid.Text = ""
98 txtname.Text = ""
99 txtaddress.Text = ""
100 txtCperson.Text = ""
101 txtcontact.Text = ""
102 txtlocal.Text = ""
103 lstProducts.Items.Clear()
104 End If
105 End Sub
106
107 Private Sub cmdadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdadd.Click
108 FrmCATEGORYSELECTitem.ShowDialog()
109 ' FrmADDSUPPLIER_ITEM.Show()
110 End Sub
111
112 Private Sub cmddelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmddelete.Click
113 If lstProducts.Items.Count > 0 Then
114 lstProducts.Focus()
115 lstProducts.FocusedItem.Remove()
116 End If
117 End Sub
118
119 Private Sub txtCperson_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCperson.KeyDown
120 'MsgBox(e.KeyCode)
121 End Sub
122
123 Private Sub txtCperson_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCperson.TextChanged
124 txtCperson.Text = str_Filter(txtCperson, 65, 122, 32, 100)
125 End Sub
126
127 Private Sub txtcontact_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcontact.TextChanged
128
129 End Sub
130
131 Private Sub txtaddress_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtaddress.TextChanged
132 txtaddress.Text = filter_Special_Char(txtaddress.Text)
133 End Sub
134
135 Private Sub txtname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtname.TextChanged
136 'txtname.Text = filter_Special_Char(str_Filter(txtname, 45, 122, 32, 150))
137 txtname.Text = filter_Special_Char(str_Filter(txtname, 45, 122, 32, 150))
138 End Sub
139 End Class